﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>咸聊</title>
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    <link rel="stylesheet" href="js/jQuery-emoji/lib/css/jquery.mCustomScrollbar.min.css" />
    <link rel="stylesheet" href="js/jQuery-emoji/lib/css/jquery.emoji.css" />
    <link href="js/layui/css/layui.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/HiChat.css" />
    <script src="js/vue.min.js"></script>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery.signalR-2.2.2.min.js"></script>
    <script src="js/jQuery-emoji/lib/script/jquery.mousewheel-3.0.6.min.js"></script>
    <script src="js/jQuery-emoji/lib/script/jquery.mCustomScrollbar.min.js"></script>
    <script src="js/jQuery-emoji/lib/script/jquery.emoji.min.js"></script>
    <script src="js/layui/layui.js"></script>
    <script>
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]); return null;
        }
        var current_uname = '';
        var current_userid = GetQueryString("userid");
    </script>
</head>
<body>
    <!--style="background-color: #4b93f9;"-->
    <!--<div class="wall-bg">
        <img src="images/background.jpg" />
    </div>-->
    <div class="container js-body" id="vue-js-app">
        <div class="row" id="js-homepage">
            <div class="col-sm-1 navbox">
                <ul class="layui-nav layui-nav-tree" style="width: 100%;">
                    <li class="layui-nav-item text-center" style="padding:49% 10% 33% 10%;">
                        <img src="images/avatar.png" width="35" height="35" />
                    </li>
                    <li class="layui-nav-item text-center" v-on:click="showHome();" v-bind:class="flag==0?'layui-this':''">
                        <i class="layui-icon layui-icon-reply-fill menu-ico"></i>
                    </li>
                    <li class="layui-nav-item text-center" @click="showuser(1)" v-bind:class="flag==1?'layui-this':''">
                        <i class="layui-icon layui-icon-friends menu-ico"></i>
                    </li>
                    <!--<li class="layui-nav-item text-center" v-on:click="shogroup(2)" v-bind:class="flag==2?'layui-this':''">
                        <i class="layui-icon layui-icon-group menu-ico"></i>
                    </li>-->
                </ul>

                <i class="layui-icon layui-icon-set-fill moretool"></i>
            </div>

            <ul class="layui-nav layui-nav-tree moretipmenu layui-hide">
                <li class="layui-nav-item" @click="logout()"><a href="javascript:;"  style="text-decoration:none;">退出</a></li>
            </ul>

            <div class="col-sm-2 userlist">
                <div class="js-main border-gray">
                    <div class="js-main-header text-white userlist-bg text-center">
                        <div class="layui-input-inline" style="width: 100%;padding: 13% 0 8% 0;">
                            <i class="layui-icon layui-icon-search searchBox-ico"></i>
                            <input type="search" name="keyword" autocomplete="off" class="layui-input searchBox userlist-avatar" placeholder="搜一搜，找一找" />
                            <i class="layui-icon layui-icon-addition plus-ico"></i>
                        </div>
                    </div>
                    <div class="js-main-body text-black userlist-bg">
                        <!--在线用户列表-->
                        <div class="js-ul-item js-tab-item" v-show="isshowusers">
                            <div class="js-li-item">
                                <!--<div class="js-fgname"><span class="js-lt text-gray">&gt;</span>在线好友</div>-->
                                <div class="js-users">
                                    <template v-for="(item,key) in onlineUserList">
                                        <template v-if="item.UserID != cnt_uid">
                                            <div class="js-user clearfix" @click="douserbyid(item.UserID,item.UserName)">
                                                <div class="js-li-img pull-left">
                                                    <span class="layui-badge-dot layui-bg-orange isnewmsg layui-hide" :id="'newmsg'+item.UserID"></span>
                                                    <img src="images/avatar.png" class="userlist-avatar" alt="" width="40" height="40" />
                                                </div>
                                                <div class="js-li-nickname pull-left">{{item.UserName}}</div>
                                                <div class="js-li-signature pull-left text-gray">全新最实用的功能全面来袭</div>
                                                <div class="pull-left text-gray datelist">6-22</div>
                                            </div>
                                        </template>
                                    </template>
                                </div>
                            </div>
                        </div>
                        <div class="js-tab-item bg-white" v-show="isshowgroup">
                            <div class="js-li-item" id="grouplist">
                                <div class="js-group-name"><span class="js-lt text-gray">&gt;</span>全部群组</div>
                                <div class="js-groups">
                                    <div class="js-room clearfix" v-for="(g,key) in groupList" @click="dochatgroup(g.RoomId,g.RoomName)">
                                        <div class="js-li-img pull-left">
                                            <img src="images/6.jpg" alt="群头像" width="40" height="40" />
                                        </div>
                                        <div class="js-li-nickname pull-left">{{g.RoomName}}</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--<div class="js-main-footer bg-grey">
                        <div class="js-btn-submit pull-left"><input type="button" @click="btnshowGroupView" value="创建群组" class="js-submit btn-primary" style="width:70px;" /></div>
                    </div>-->
                </div>
            </div>

            <!------大厅窗口-------->
            <div class="col-sm-9" v-show="chatpanel" style="padding:0;">
                <div class="js-chat text-white border-gray">
                    <div class="js-chat-header bg-gray text-center clearfix">
                        <div class="js-txt-nickname pull-left">一起咸聊</div>
                    </div>
                    <!--聊天记录-->
                    <div class="js-chat-body bg-gray" style="overflow:auto" v-html="joinhtml"></div>
                    <div class="js-chat-footer clearfix bg-white" style="height: 160px;">
                        <div class="js-emoji">
                            <!--<input type="image" value="Emoji" id="btnEmoji" class="btnEmoji" onclick="InitEmoji('txtPubMsg','btnEmoji')" src="js/jQuery-emoji/lib/img/emoji.png" />
                            <input type="image" value="pic" id="btnpubpic" class="btnEmoji" src="js/jQuery-emoji/lib/img/picture.png" />
                            <input type="image" value="Emoji" id="btnEmoji" class="btnEmoji" src="js/jQuery-emoji/lib/img/file.png" />-->

                            <span id="btnEmoji" value="Emoji" class="chose_btn chose_emoji_btn btnEmoji" onclick="InitEmoji('txtPubMsg','btnEmoji')"></span>
                            <span id="chose_pic_btn" class="chose_btn chose_pic_btn btnEmoji">
                                <input id="uppic" type="file" name="files" accept="image/*" />
                            </span>
                        </div>
                        <div class="js-text-msg pull-left no-input-msg">
                            <div id="txtPubMsg" v-model="txtPubMsg" contenteditable="true" class="js-chat-div" @focus="intipstate(0,$event)" @blur="outtipstate(0,$event)"></div>
                        </div>
                        <input type="button" name="btnSend" id="btnSend" value="发送" class="js-submit btn-primary" v-on:click="btnSend()" />
                    </div>
                </div>
            </div>

            <!------私聊好友窗口--------->
            <div class="col-sm-9" v-show="chatfriends" style="padding:0;">
                <div class="js-chat text-white border-gray">
                    <div class="js-chat-header bg-gray text-center clearfix">
                        <div class="js-txt-nickname pull-left" v-html="friendname"></div>
                        <!--<div class="js-div-close pull-right"><a href="javascript:;" class="text-white js-a-close" @click="showHome();">关闭</a></div>-->
                        <input type="hidden" value="" v-model="hid_touserid" />
                    </div>
                    <!--聊天记录-->
                    <div class="js-chat-body bg-gray" style="overflow:auto" v-html="frihtml"></div>
                    <div class="js-chat-footer clearfix bg-white" style="height: 160px;">
                        <div class="js-emoji">
                            <input type="image" value="Emoji" id="btnSEmoji" class="btnEmoji" onclick="InitEmoji('txtfriendMsg','btnSEmoji')" src="js/jQuery-emoji/lib/img/emoji.png" />
                            <input type="image" value="Emoji" id="btnSPic" class="btnEmoji" src="js/jQuery-emoji/lib/img/picture.png" />
                            <input type="image" value="Emoji" id="btnSFile" class="btnEmoji" src="js/jQuery-emoji/lib/img/file.png" />
                        </div>
                        <div class="js-text-msg pull-left no-input-msg">
                            <div id="txtfriendMsg" v-model="txtfriendMsg" contenteditable="true" class="js-chat-div" @focus="intipstate(1,$event)" @blur="outtipstate(1,$event)"></div>
                        </div>
                        <input type="button" name="btnFriendSend" value="发送" class="js-submit btn-primary" @click="btnFriendSend()" />
                    </div>
                </div>
            </div>

            <!------群组聊天窗口--------->
            <div class="col-sm-9" v-show="chatgroups">
                <div class="js-chat text-white border-gray">
                    <div class="js-chat-header bg-gray text-center clearfix">
                        <div class="js-txt-nickname pull-left">{{group_title}}</div>
                        <div class="js-div-close pull-right"><a href="javascript:;" class="text-white js-a-close" @click="showHome()">退出</a></div>
                        <input type="hidden" v-model="hid_roomid" />
                    </div>
                    <div class="js-chat-body bg-gray" style="height:550px;width:847px;overflow:auto" v-html="grouphtml">

                    </div>
                    <div class="js-chat-footer clearfix bg-white">
                        <div class="js-text-msg pull-left" style="width:90%;"><input type="text" v-model="txtgroupmsg" placeholder="对大家说点啥" class="js-text" /></div>
                        <div class="js-btn-submit pull-right"><input type="button" @click="btnGroupdSend()" value="发送" class="js-submit btn-primary" /></div>
                    </div>
                </div>
            </div>
        </div>
        <!--创建群组模态框-->
        <div v-show="shomdal" class="modal fade in" id="groupModal" tabindex="-1" role="dialog" aria-labelledby="groupModal" style="display:block">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" @click="closegroupView()">
                            <span aria-hidden="true">×</span>
                        </button>
                        <h4 class="modal-title" id="exampleModalLabel">创建群组</h4>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="recipient-name" class="control-label">群组名称:</label>
                                <input type="text" class="form-control" placeholder="请输入群组名称" v-model="groupname">
                                <label class="control-label" style="color:red">{{group_errmsg}}</label>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" @click="closegroupView()">关闭</button>
                        <button type="button" class="btn btn-primary" @click="creategroup()">创建</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    //聊天记录集合
    var pubhistoryList = [];
    var onlineUserList = []; //在线用户集合
    var groupList = [];//群组集合
    var prihistoryList = [];//私聊历史记录
    var groupHistoryList = [];//群聊天记录

    new Vue({
        el: '#vue-js-app',
        data: {
            onlineUserList: onlineUserList,
            cnt_uname: current_uname,
            cnt_uid: current_userid,
            txtPubMsg: '',
            txtfriendMsg: '',
            pubhistoryList: pubhistoryList,
            isshowusers: false,
            isshowgroup: false,
            isshowfrihistory: false,
            chatpanel: true,
            chatfriends: false,
            chatgroups: false,
            hid_touserid: '',//好友聊天id
            prihistoryList: prihistoryList,
            friendname: '',
            groupHistoryList: groupHistoryList,
            groupname: '',
            shomdal: false,
            group_errmsg: '',
            groupList: groupList,
            hid_roomid: '',
            joinhtml: '',
            frihtml: '',
            grouphtml: '',
            group_title: '',
            txtgroupmsg: '',
            flag: 0,
            proxy: []
        },
        //监听
        computed: {

        },
        created() {
            this.initdata();
        },
        methods: {
            initdata: function () {
                var conn = $.hubConnection("http://localhost:7123/signalr");
                var proxy = conn.createHubProxy("chatHub");
                this.proxy = proxy;

                this.proxy.on('returnLogin', () => {
                    //window.location.href = "login.html";
                    window.location.href = "sign.html";
                });

                //获取当前登陆用户信息
                this.proxy.on('queryUinfoById', (username, userid) => {
                    current_uname = username, this.cnt_uname = username;
                    current_userid = userid, this.cnt_uid = userid;
                });

                //在线用户列表
                proxy.on('showUserList', data => {
                    this.onlineUserList = data;
                });

                //群组列表
                proxy.on('showAllRoomList', data => {
                    this.groupList = data;
                });

                //显示聊天记录
                proxy.on('sendPublicMessage', (userid, username, message, dt) => {
                    var direction = userid === current_userid ? 'right' : 'left';
                    var str = '<div class="js-time text-white text-center"><span>' + dt + '</span></div>'
                        + '<div class="col-sm-12"><div class="js-msg-' + direction + ' clearfix text-black"><div class="js-msg-img pull-' + direction + '">'
                        + '<img src="/Images/avatar.jpg" width="40" height="40" /></div><div class="pull-' + direction + ' padbox">'//+'<div class="js-msg-nick text-' + direction + '">' + username + '</div>'
                        + '<div class="js-msg-info ' + (direction == "left" ? "chat-single-left-bg" : "chat-single-right-bg") + '">' + message + '</div></div></div></div>';
                    this.joinhtml += str;
                });

                //显示好友消息
                this.proxy.on('showMsgToPages', (frmuid, sendname, message, dt) => {
                    this.getPriMsgHtml(frmuid, sendname, message, dt);
                });

                //显示好友接收到消息
                this.proxy.on('remindMsg', (frmuid, frmuname, message, dt) => {
                    if (this.cnt_uid != frmuid) {
                        if ($("#newmsg" + frmuid).hasClass("layui-hide")) {
                            $("#newmsg" + frmuid).removeClass("layui-hide");
                        }
                    }

                    if (this.hid_touserid != frmuid)//如果当前聊天的id不相同
                    {
                        this.proxy.invoke('getChatHistory', 1, frmuid, current_userid, '');
                        this.hid_touserid = frmuid;
                        this.friendname = frmuname;
                        this.chatpanel = false;
                        this.chatfriends = true;
                        this.chatgroups = false;
                    } else {
                        this.getPriMsgHtml(frmuid, frmuname, message, dt);
                    }
                });

                //获取聊天记录
                this.proxy.on('initChatHistoryData', (data, chattype) => {
                    switch (chattype) {
                        case 0://公共聊天记录
                            // this.pubhistoryList = data;
                            this.joinhtml = this.getStrHtml(data);
                            break;
                        case 1://私聊
                            // this.prihistoryList = data;
                            this.frihtml = this.getStrHtml(data);
                            break;
                        case 2://群聊天
                            this.grouphtml = this.getStrHtml(data);
                            //this.groupHistoryList = data;
                            break;
                        default:
                            break;
                    }
                });

                //显示创建群组消息提示
                this.proxy.on('showGroupMsg', (state) => {
                    if (state == "success") {
                        this.shomdal = false;
                    } else {
                        this.group_errmsg = '已存在相同名称的群组';
                    }
                });

                //显示加入群组系统消息
                this.proxy.on('showSysGroupMsg', username => {
                    this.grouphtml += '<div class="js-time text-white text-center"><span>' + username + '加入了聊天</span></div>';
                });

                //显示提示消息
                this.proxy.on('showMessage', message => {
                    alert(message);
                });

                //显示群组消息
                this.proxy.on('showGroupByRoomMsg', (username, roomid, message, dt) => {
                    if (this.hid_roomid == roomid && this.hid_roomid != "" && this.hid_roomid != "undefined") {
                        var str = '';
                        var direction = username === current_uname ? 'right' : 'left';
                        var str = '<div class="js-time text-white text-center"><span>' + dt + '</span></div>' +
                            '<div class="col-sm-12"><div class="js-msg-' + direction + ' clearfix text-black"><div class="js-msg-img pull-' + direction + '">'
                            + '<img src="/Images/avatar.jpg" width="40" height="40" /></div><div class="pull-' + direction + ' padbox">'
                            //+'<div class="js-msg-nick text-' + direction + '">' + username + '</div>'
                            + '<div class="js-msg-infog ' + (direction == "left" ? "chat-single-left-bg" : "chat-single-right-bg") + '">' + message + '</div></div></div></div>';
                        this.grouphtml += str;
                    }
                });

                conn.start({ xdomain: true })
                    .done(function () {
                        //添加在线用户
                        proxy.invoke("queryUinfoById", current_userid);
                        //获取用户集合
                        proxy.invoke('getAllOnlineUser');
                        //获取群组集合
                        proxy.invoke('updateAllRoomList');

                        proxy.invoke('getChatHistory', 0, '', current_userid, '');

                    })
                    .fail(function () {
                        console.log("Could not connect");
                    });
            },
            logout: function () {
                window.location.href = "sign.html";
            },
            //消息聚焦
            intipstate: function (t, e) {
                var curObj = e.currentTarget;
                if (t != 0) {
                    var pobj = curObj.parentElement;
                    if (this.friendname != "") {
                        $("#txtfriendMsg").attr("contenteditable", "true");
                        if ($(pobj).hasClass("no-input-msg")) {
                            $(pobj).removeClass("no-input-msg");
                        }
                    }
                    else {
                        $("#txtfriendMsg").attr("contenteditable", "false");
                    }
                    var _fid = this.hid_touserid;
                    if (!$("#newmsg" + _fid).hasClass("layui-hide")) {
                        $("#newmsg" + _fid).addClass("layui-hide");
                    }
                } else {
                    var pobj = curObj.parentElement;
                    if ($(pobj).hasClass("no-input-msg")) {
                        $(pobj).removeClass("no-input-msg");
                    }
                }
            },
            //消息失焦
            outtipstate: function (t, e) {
                var pobj = e.currentTarget.parentElement;
                if (t != 0) {
                    if (this.friendname != "") {
                        if (!$(pobj).hasClass("no-input-msg")) {
                            $(pobj).addClass("no-input-msg");
                        }
                    }
                } else {
                    if (!$(pobj).hasClass("no-input-msg")) {
                        $(pobj).addClass("no-input-msg");
                    }
                }
            },
            //大厅聊天发送
            btnSend: function () {
                var _chatContent = $("#txtPubMsg").html();
                this.txtPubMsg = _chatContent;
                //var cahtTxt = replace_em(_chatContent);
                if (this.txtPubMsg == "" || this.txtPubMsg == undefined || this.txtPubMsg == null) {
                    alert("请输入聊天信息");
                } else {
                    this.proxy.invoke('publicSendMsg', this.txtPubMsg, current_userid);
                    this.txtPubMsg = '';
                    $("#txtPubMsg").html("");
                }
            },
            //大厅
            showHome: function (index) {
                this.proxy.invoke('getChatHistory', 0, '', current_userid, '');
                this.chatpanel = true;
                this.chatfriends = false;
                this.chatgroups = false;
                this.hid_touserid = '';
                this.hid_roomid = '';
                this.isshowusers = false;
                this.flag = 0;
            },
            //好友
            showuser: function (index) {
                this.isshowusers = true;
                this.isshowgroup = false;
                this.chatpanel = false;
                this.chatfriends = true;
                this.isshowfrihistory = true;
                this.flag = 1;
            },
            //群组
            shogroup: function (index) {
                this.isshowusers = false;
                this.isshowgroup = true;
                this.hid_touserid = '';
                this.flag = 2;
            },
            //点击选择好友事件
            douserbyid: function (toid, username) {
                if (toid != "undefined") {
                    if (toid != current_userid) {
                        this.proxy.invoke('getChatHistory', 1, toid, current_userid, '');
                        this.friendname = '<span> ' + username + '</span>';
                        this.hid_touserid = toid;
                        this.chatpanel = false;
                        this.chatfriends = true;
                        this.chatgroups = false;

                        $("#txtfriendMsg").attr("contenteditable", "true");
                        if ($("#txtfriendMsg").parent().hasClass("no-input-msg")) {
                            $("#txtfriendMsg").parent().removeClass("no-input-msg");
                        }
                    }
                    else {
                        alert("个人设置正在开发中");
                    }
                }
            },
            //发送好友消息
            btnFriendSend: function () {
                //var msg = this.txtfriendMsg.trim();
                this.txtfriendMsg = $("#txtfriendMsg").html();
                if (this.hid_touserid == null || this.hid_touserid == "" || this.hid_touserid == "undefined") {
                    alert("请选先择交流对象");
                }
                else if (this.txtfriendMsg == null || this.txtfriendMsg == "" || this.txtfriendMsg == "undefined") {
                    alert("请输入聊天记录");
                } else {
                    this.proxy.invoke('sendPrivateMsg', current_uname, this.hid_touserid, this.txtfriendMsg);
                    this.txtfriendMsg = '';
                    $("#txtfriendMsg").html("");
                }
            },
            getPriMsgHtml: function (userId, sendname, message, dt) {
                var str = '';
                //拼接聊天记录
                var direction = userId === current_userid ? 'right' : 'left';
                message = formatImg(message);
                str = '<div class="js-time text-white text-center"><span>' + dt + '</span></div> '
                    + '<div class="col-sm-12"><div class="js-msg-' + direction + ' clearfix text-black"><div class="js-msg-img pull-' + direction + '">'
                    + '<img src="/Images/avatar.jpg" width="40" height="40" /></div>'
                    + '<div class="pull-' + direction + ' padbox">' //+'<div class="js-msg-nick text-' + direction + '">' + sendname + '</div>'
                    + '<div class="js-msg-info ' + (direction == "left" ? "chat-single-left-bg" : "chat-single-right-bg") + '">' + message + '</div></div></div></div>';
                this.frihtml += str;
            },
            //获取字符串拼接
            getStrHtml: function (list) {
                var str = '';
                if (list != null && list != "") {
                    for (var i = 0; i < list.length; i++) {
                        var direction = list[i].frmId === current_userid ? 'right' : 'left';
                        list[i].Message = formatImg(list[i].Message);
                        str += '<div class="js-time text-white text-center"><span>' + list[i].msgTime + '</span></div>'
                            + '<div class="col-sm-12"><div class="js-msg-' + direction + ' clearfix text-black"><div class="js-msg-img pull-' + direction + '">'
                            + '<img src="/Images/avatar.jpg" width="40" height="40" /></div><div class="pull-' + direction + ' padbox">'//+'<div class="js-msg-nick text-' + direction + '">' + list[i].UserName + '</div>'
                            + '<div class="js-msg-info ' + (direction == "left" ? "chat-single-left-bg" : "chat-single-right-bg") + '">' + list[i].Message + '</div></div></div></div>';
                    }
                }
                return str;
            },
            //弹出框
            btnshowGroupView: function () {
                this.shomdal = true;
            },
            //创建群组
            creategroup: function () {
                name = this.groupname.trim();
                if (name == '' || name == "undefined" || name == null) {
                    this.group_errmsg = '请输入群组名称';
                } else {
                    this.proxy.invoke('createRoom', name);
                    this.group_errmsg = '';
                }
            },
            //关闭群组弹出框
            closegroupView: function () {
                this.shomdal = false;
            },
            //点击单个群组聊天
            dochatgroup: function (roomId, roomName) {
                if (roomId != "undefined" && roomId != "") {
                    this.proxy.invoke('getChatHistory', 2, '', current_userid, roomId);
                    this.hid_roomid = roomId;
                    this.chatgroups = true;
                    this.chatfriends = false;
                    this.chatpanel = false;
                    this.group_title = '' + roomName;
                    this.proxy.invoke('joinRoom', roomId, current_userid);
                }
            },
            //发送群组聊天
            btnGroupdSend: function () {
                var roomid = this.hid_roomid;
                var msg = this.txtgroupmsg.trim();
                if (msg != null && msg != "" && msg != "undefined") {
                    if (roomid != "" && roomid != null && roomid != "undefined") {
                        this.proxy.invoke('sendMessageByRoom', roomid, current_userid, msg);
                        this.txtgroupmsg = '';
                    } else {
                        alert('房间id不存在');
                    }
                } else {
                    alert('请输入消息');
                }
            }
        }
    });

    layui.config({ base: '/js/layui/lay/modules/' }).use(['element', 'layer', 'jquery', 'form', 'upload'], function () {
        var $ = layui.jquery, layer = layui.layer;
        $(function () {
            $(".js-chat-body").on("click", ".js-msg-info img[class!='emoji_icon']", function () {
                layer.photos({ photos: ".chatpicbox" });
            });

            $("#chose_pic_btn").click(function () {
                $("#uppic").click();
            });

            $(".moretool").click(function () {
                if ($(".moretipmenu").hasClass("layui-hide")) {
                    $(".moretipmenu").removeClass("layui-hide");
                }
            });
        });
    });

    //初始化Emoji
    function InitEmoji(msgid, btnid) {
        if (msgid == undefined || btnid == undefined) {
            msgid = "txtPubMsg";
            btnid = "btnEmoji";
        }
        $("#" + msgid).emoji({
            button: "#" + btnid,
            showTab: false,
            animation: 'none',
            position: "topRight",
            icons: [{
                path: "js/jQuery-emoji/lib/img/qq/",
                maxNum: 91,
                excludeNums: [41, 45, 54],
                file: ".gif",
                placeholder: "#qq_{alias}#"
            }]
        });
    }

    //转换图片资源
    function formatImg(_html) {
        var imgs = _html.match(/<img.+?>/ig);
        if (imgs != null) {
            var _len = imgs.length;
            for (var n = 0; n < _len; n++) {
                var imgObj = imgs[n];
                if (!$(imgObj).hasClass("emoji_icon")) {
                    var newImg = "<div class='chatpicbox'>" + imgObj + "</div>";
                    _html = _html.replace(imgObj, newImg);
                }
            }
        }
        return _html;
    }
</script>